<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        type="password"
        name="oldPassword"
        label="旧密码"
        placeholder="跳过这行，直接输入新密码"
      />
      <van-field
        v-model="NewPassword"
        type="password"
        name="NewPassword"
        label="新密码"
        placeholder="请输入新密码"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from 'vant';
import { InfoAPI, AlertPassword } from '../service/user';

export default {
  name: 'WorkspaceJsonAlertPassword',

  data() {
    return {
      oldPassword: '',
      NewPassword: '',
      userList: {},
    };
  },

  mounted() {},
  async created() {
    const res = await InfoAPI();
    this.userList = res.data.data;
    console.log(this.userList);
  },

  methods: {
    async onSubmit(values) {
      console.log(values);
      const res1 = await AlertPassword({
        oldPassword: this.userList.password,
        NewPassword: values.NewPassword,
      });
      console.log(res1);
      if (res1.data.code === 1) {
        Toast.success(res1.data.msg);
        setTimeout(() => {
          this.$router.push({
            name: 'VueYimutianLogin',
          });
        }, 2000);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
